(defun count-letters (n)
  (let ((sum 0))
  (loop for char across (format nil "~r" n) 
     when (and (not (eq char #\ )) (not (eq char #\-))) 
     do (setq sum (1+ sum))
       finally (return sum))))

(defun count-letters-until (n)
  (let ((sum 0))
    (loop for i from 1 to n do 
	 (if (or (<= i 100) (eq (mod i 100) 0) )
	     ;(format t  "number ~d has ~d~%" i (count-letters i))
	     (setq sum (+ sum (count-letters i)))
	     ;(format t  "number ~d has ~d~%" i (count-letters i)))
	      (setq sum (+ sum 3 (count-letters i))))
	     
       finally (return sum))))

(defun count-letters-until-2 (n)
  (let ((sum 0))
    (loop for i from 1 to n do 
	     (setq sum (+ sum (count-letters i)))
       finally (return sum))))

(defun letters (num)
  (remove-if
   #'(lambda (str) (or (equal str " ") (equal str "-")))
   (map 'list
        #'(lambda (char) (string char))
        (format nil "~R" num))))

(defun euler17 ()
  (length (loop for i from 1 to 1000
                append (letters i))))